//
//  BaseViewController.swift
//  XingCeHelper
//
//  Created by 申铭 on 2022/10/20.
//

import UIKit

class BaseViewController: UIViewController {
    
    /// 生成唯一标识，表示这一次的所有计时，都是同一事件
    var uuid = UUID().uuidString
    /// 计时器
    var timer: Timer?
    /// 数据个数
    var dataCount: Int = 0

    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        if timer != nil {
            timer?.invalidate()
            timer = nil
        }
    }
    
    /// 设置Timer
    /// - Parameter count: 数量大于1，则开启计时
    func setupTimer(count: Int) {
        if timer != nil { return }
        if count == 0 { return }
        
        self.timer = Timer.scheduledTimer(timeInterval: 1.0, target:self, selector: #selector(self.timing), userInfo: nil, repeats: true)
        if let t = self.timer {
            RunLoop.main.add(t, forMode: .common)
        }
    }
    
    func pauseTimer() {
        timer?.fireDate = Date.distantFuture
    }
    
    func startTimer() {
        timer?.fireDate = Date.distantPast
    }
    
    @objc func timing() {
//        print("timing")
    }
}
